﻿#region Imports
using System;
using System.Collections.ObjectModel;
using System.Linq;
#endregion Imports

namespace Domino
{
    public class PlayerModel : BaseViewModel
    {
        #region Properties
        private bool isEnabled;
        public bool IsEnabled
        {
            get { return isEnabled; }
            set { isEnabled = value; RaisePropertyChanged("IsEnabled"); }
        }

        private string label;
        public string Label
        {
            get { return label; }
            set { label = value; RaisePropertyChanged("Label"); }
        }

        private string name;
        public string Name
        {
            get { return name; }
            set { name = value; RaisePropertyChanged("Name"); }
        }

        private ObservableCollection<TileModel> tiles_org = new ObservableCollection<TileModel>();
        public ObservableCollection<TileModel> Tiles_org
        {
            get { return tiles_org; }
            set
            {
                tiles_org = value;
                RefreshPlayerTiles();
            }
        }

        private ObservableCollection<TileModel> tiles = new ObservableCollection<TileModel>();
        public ObservableCollection<TileModel> Tiles
        {
            get { return new ObservableCollection<TileModel>(tiles_org.Where(t => t.TileLocation == eTileLocation.Player).ToList()); }
        }

        private bool isCurrent = true;
        public bool IsCurrent
        {
            get { return isCurrent; }
            set { isCurrent = value; RaisePropertyChanged("IsCurrent"); }
        }

        private int score;
        /// <summary>
        /// Player's score
        /// </summary>
        public int Score
        {
            get { return score; }
            set { score = value; RaisePropertyChanged("Score"); }
        }

        private int boardScore;
        public int BoardScore
        {
            get { return boardScore; }
            set { boardScore = value; RaisePropertyChanged("BoardScore"); }
        }

        private int residualScore;
        public int ResidualScore
        {
            get { return residualScore; }
            set { residualScore = value; RaisePropertyChanged("ResidualScore"); }
        }

        private bool isPassEnabled;
        public bool IsPassEnabled
        {
            get { return isPassEnabled; }
            set { isPassEnabled = value; RaisePropertyChanged("IsPassEnabled"); }
        }
        #endregion Properties

        #region Methods
        internal void RefreshPlayerTiles()
        {
            RaisePropertyChanged("Tiles");
        }

        public override string ToString()
        {
            return String.Format("{0}, Score: {1}, Board/Residual: {2}/{3}, Playable: {4}/{5}",
                this.Name, this.Score, this.BoardScore, this.ResidualScore, this.Tiles.Where(t => t.IsPlayable).Count(), this.Tiles.Count());
        }
        #endregion Methods
    }
}
